﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.责任链模式
{
    public class ChainPatternDemo
    {
        private static AbstractLogger ChainOfLoggers()
        {
            AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);
            AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG);
            AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO);

            errorLogger.NextLogger = fileLogger;
            fileLogger.NextLogger = consoleLogger;

            return errorLogger;
        }

        public static void Test()
        {
            AbstractLogger loggerChain = ChainOfLoggers();

            loggerChain.LogMessage(AbstractLogger.INFO, "This is an infomation.");
            loggerChain.LogMessage(AbstractLogger.DEBUG, "This is a debug level information.");
            loggerChain.LogMessage(AbstractLogger.ERROR,"This is an error information.");
        }
    }
}
